import os

def pair(args):
	for i in range(len(args)):
		for b in args[i+1:]:
			yield (args[i],b)


#agents
players = ['smartscoremax', 'stabab', 'mobstabab']
score = {'mobstabab':0,
	 'smartscoremax':0,
	 'stabab':0}

#othello commands
cmd=["othellosim -b %(p1)s -w %(p2)s -g 3 -t %(t)d -o %(o1)s",
     "othellosim -b %(p2)s -w %(p1)s -g 3 -t %(t)d -o %(o2)s"]

d = {'p1':'',
     'p2':'',
     't':1000,
     'o1':"%(p1)s-Vs-%(p2)s-%(t)d.txt",
     'o2':"%(p2)s-Vs-%(p1)s-%(t)d.txt"}

for d['p1'], d['p2'] in pair(players):
	map(lambda l : os.system(l %d %d), cmd)

stats = open('resultsr3.txt','w')

for p1, p2 in pair(players):
	out = open('%s-Vs-%s-1000.txt'%(p1, p2))
	for line in out:
		if line[:5] == "Black":
			score[p1] += 1
		elif line[:5] == "White":
			score[p2] += 1
	out.close()
	out = open('%s-Vs-%s-1000.txt'%(p2, p1))
	for line in out:
		if line[:5] == "Black":
			score[p2] += 1
		elif line[:5] == "White":
			score[p1] += 1
	out.close()

for player in players:
	stats.write("%s:  %d\n" % (player, score[player]))

stats.close()
